//v.1.6 build 9757
/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
var dhtmlXVaultObject = function () {
	var nav = navigator.appName;
	this.IE = nav.indexOf("Explorer") > -1;
	this.Opera = nav.indexOf("Opera") > -1;
	this.isUploadFile = false;
	this.isUploadFileAll = false;
	this.counter = 1;
	this.idRowSelected = null;
	this.sessionId = null;
	this.pathUploadHandler = null;
	this.pathGetInfoHandler = null;
	this.pathGetIdHandler = null;
	this.imPath = "imgs/";
	this.strings = {remove:"删除", upload:"上传", done:"完成", error:"错误", btnAdd:"添加文件", btnUpload:"上传", btnClean:"清空", btnClose:"关闭"};
	this.strings.errors = {"TooBig":"File is too big ({0};bytes).\nMax allowed size is {1}.", "PostSize":"Undefined server error. Possible issues:\n- Unicode file name incorrectly processed by the server;\n- File size is bigger than server's post-request limit ({0})."};
	this.filesLimit = 0;
	this.fileList = {};
	this.uploadedCount = 0;
	this.progressDemo = null;
	this.inpMAX_FILE_SIZE = null;
	this.MAX_FILE_SIZE =  5*1024*1024;
	this.inpUPLOAD_IDENTIFIER = null;
	this.fileType = null;//文件类型
	this.fileGrade = null;
	this.modelValue = null;//模块
	this.modelRecordId = null;//模块记录主键ID
	this.businessType = null;//文件业务类型
	this.fileExtensionStr = "jpg;png;gif;bmp;jpeg;doc;docx;txt;xls;xlsx;php;rar;";//默认上传文件扩展名
	this.fileExtensionList = this.fileExtensionStr.split(';');
	this.saveFilePath = null;//上传文件保存路径
	this.imgType="jpg;png;gif;bmp;jpeg;";//图片
	this.documentType="doc;docx;txt;xls;xlsx";//文档
	this.compressType = "rar;war;";//压缩包
	this.video_frequency = "flv;swf;wmv;rmvb;rm";//视频
	this.otherType = "图片:"+this.imgType+" 文档:"+this.documentType+" 视频:"+this.video_frequency+" 压缩包:"+this.compressType;
};
dhtmlXVaultObject.prototype.setServerHandlers = function (uploadHandler, getInfoHandler, getIdHandler) {
	this.pathUploadHandler = uploadHandler;
	this.pathGetInfoHandler = getInfoHandler;
	this.pathGetIdHandler = getIdHandler;
};
dhtmlXVaultObject.prototype.copyFileType = function (fileType) {
	this.fileType = fileType;
};
dhtmlXVaultObject.prototype.setSaveFilePath = function (saveFilePath) {
		this.saveFilePath = saveFilePath;
};
dhtmlXVaultObject.prototype.setFileExtensionList = function (fileExtensionStr) {
	if(fileExtensionStr!=null&&fileExtensionStr!="")
	{
		this.fileExtensionList = fileExtensionStr.split(';');
		this.fileExtensionStr = fileExtensionStr;
	}
};
dhtmlXVaultObject.prototype.copyFileGrade = function (fileGrade) {
	
	this.fileGrade = fileGrade;
};
dhtmlXVaultObject.prototype.setModelRecordId = function (modelRecordId) {
	this.modelRecordId = modelRecordId;
};
dhtmlXVaultObject.prototype.setModelValue = function (modelValue) {
	
	this.modelValue = modelValue;
};
dhtmlXVaultObject.prototype.setBusinessType = function (businessType) {
	
	this.businessType = businessType;
};
dhtmlXVaultObject.prototype.setMaxFileSize = function (maxFileSize) {
	
	this.MAX_FILE_SIZE = maxFileSize;
};

dhtmlXVaultObject.prototype.setImagePath = function (newPath) {
	this.imPath = newPath;
	this.preLoadImages();
};
dhtmlXVaultObject.prototype.create = function (htmlObject) {
	this.parentObject = document.getElementById(htmlObject);
	this.parentObject.style.position = "relative";
	this.parentObject.innerHTML = "<iframe src='about:blank' id='dhtmlxVaultUploadFrame' name='dhtmlxVaultUploadFrame' style='display:none;position:absolute;left:-1000px;width:1px;height:1px'></iframe>";
	this.containerDiv = document.createElement("div");
	this.containerDiv.className = "dhxvlt_panel2border";
	this.containerDiv.style.cssText = "position:absolute;overflow-y:auto;height:190px;background-color:#FFFFFF;top:10px;left:2px;z-index:10;width:428px";
	
	
	this.parentObject.appendChild(this.containerDiv);
	this.container = document.createElement("div");
	this.container.style.position = "relative";
	this.container.innerHTML = "<table class=' ' border='0'>" + "<tr><td  align='center' id='cellContainer'>" + "<div style='height:200px'></div>" + "</td></tr>" + "<tr><td style='width:110px;height:32px' align='left'></td>" + "<td style='width:190px;height:32px' align='left'>" + "<div class='dhxvlt_lbtn'><span class='dhxvlt_lbtn1'></span><span class='dhxvlt_lbtn2'><nobr><img src='" + this.imPath + "upload.gif'/> " + this.strings.btnUpload + "</nobr></span><span class='dhxvlt_lbtn3'></span></div></td>" +"<td style='width:70px;height:32px;' align='right'>" + "<div class='dhxvlt_rbtn'><span class='dhxvlt_rbtn3'></span><span class='dhxvlt_rbtn2'><nobr><img src='" + this.imPath + "clean.gif'/> " + this.strings.btnClean + "</nobr></span><span class='dhxvlt_rbtn1'></span></div></td><td style='width:70px;height:32px;' align='left'><div class='dhxvlt_rbtn'><span class='dhxvlt_rbtn3'></span><span class='dhxvlt_rbtn2'><nobr><img src='" + this.imPath + "close.gif'/>&nbsp;"   + this.strings.btnClose + "</nobr></span><span class='dhxvlt_rbtn1'></span></div></td></tr></table>" + "<div class='btnAddBtn dhxvlt_lbtn'><span class='dhxvlt_lbtn1'></span><span class='dhxvlt_lbtn2'  onclick='fileClick();'><nobr><img src='" + this.imPath + "add.gif'/> "  + this.strings.btnAdd + "</nobr></span><span class='dhxvlt_lbtn3'></span></div>" + "<div class='btnAddDiv'>" + "<input type='file' id='file1' name='file1' value='' class='dhxvlt_hidden" + (this.Opera ? "dhxvlt_fo" : "") + "'/></div>";
	this.parentObject.appendChild(this.container);
	var self = this;
	this.container.childNodes[0].rows[1].cells[1].childNodes[0].onclick = function () {
		self.uploadAllItems();
	};
	this.container.childNodes[0].rows[1].cells[2].childNodes[0].onclick = function () {
		self.removeAllItems();
	};
	this.container.childNodes[0].rows[1].cells[3].childNodes[0].onclick = function () {
		closeUploadFileWindow();
	};
	this.fileContainer = this.container.childNodes[2];
	this.currentFile = this.fileContainer.childNodes[0];
	this.currentFile.onchange = function () {
		self.addFile();
	};
	if (this.IE) {
		this.uploadForm = document.createElement("<form enctype='multipart/form-data' target='dhtmlxVaultUploadFrame' method='post' id='uploadForm'>");
	} else {
		this.uploadForm = document.createElement("form");
		this.uploadForm.method = "post";
		this.uploadForm.encoding = "multipart/form-data";
		this.uploadForm.target = "dhtmlxVaultUploadFrame";
	}
	this.container.appendChild(this.uploadForm);
	this.inpMAX_FILE_SIZE = document.createElement("input");
	this.inpMAX_FILE_SIZE.type = "hidden";
	this.inpMAX_FILE_SIZE.name = "xMAX_FILE_SIZE";
	this.inpMAX_FILE_SIZE.value = this.MAX_FILE_SIZE;
	this.uploadForm.appendChild(this.inpMAX_FILE_SIZE);
	this.inpUPLOAD_IDENTIFIER = document.createElement("input");
	this.inpUPLOAD_IDENTIFIER.type = "hidden";
	this.inpUPLOAD_IDENTIFIER.name = "UPLOAD_IDENTIFIER";
	this.uploadForm.appendChild(this.inpUPLOAD_IDENTIFIER);
	this.tblListFiles = null;
	this.tblProgressBar = this.createProgressBar();
	this.percentPanel = this.createPercentPanel();
	this.containerDiv.appendChild(this.percentPanel);
	this.progressDemo = this.createProgressDemo();
};
dhtmlXVaultObject.prototype.createXMLHttpRequest = function () {
	var xmlHttp = null;
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		if (window.XMLHttpRequest) {
			xmlHttp = new XMLHttpRequest();
		}
	}
	return xmlHttp;
};
dhtmlXVaultObject.prototype.getFileName = function (path) {
    
	var arr = path.split("\\");
	path = arr[arr.length - 1];
	arr = path.split("/");
	return arr[arr.length - 1];
};
dhtmlXVaultObject.prototype.selectItem = function (currentId) {
	var currentRow = this.getCurrentRowListFiles(currentId);
	if (this.idRowSelected) {
		var row = this.getCurrentRowListFiles(this.idRowSelected);
		if (row) {
			if (row.id != currentRow.id) {
				currentRow.className = "dhxvlt_rowsel";
				this.idRowSelected = currentId;
				row.className = "dhxvlt_row";
			} else {
				currentRow.className = "dhxvlt_row";
				this.idRowSelected = "";
			}
		} else {
			currentRow.className = "dhxvlt_rowsel";
			this.idRowSelected = currentId;
		}
	} else {
		currentRow.className = "dhxvlt_rowsel";
		this.idRowSelected = currentId;
	}
};
dhtmlXVaultObject.prototype.enableAddButton = function (enabled) {
	this.currentFile.disabled = !enabled;
	var btn = this.currentFile.parentNode.previousSibling.childNodes[1].childNodes[0].childNodes[0];
	btn.src = this.imPath + (enabled ? "add.gif" : "close.gif");
	btn.parentNode.className = enabled ? "" : "dhxvlt_dis";
};
dhtmlXVaultObject.prototype.checkFilesLimit = function () {
	if (this.filesLimit > 0) {
		var n = this.getTotalFilesCount();
		this.enableAddButton(n < this.filesLimit);
	}
};
dhtmlXVaultObject.prototype.addFile = function () {
	var file = this.currentFile;
	var filePath = file.value;
	try {
		if (file.value == "") {
			return;
		}
		if (!this.onAddFile(file.value)) {
			file.value = "";
			return;
		}
	}
	catch (e) {
	}
	var currentId = this.createId();
	this.fileList[currentId] = {id:currentId, name:file.value, uploaded:false, error:false};
	file.disabled = true;
	file.style.display = "none";
	this.uploadForm.appendChild(file);
	var newInputFile = document.createElement("input");
	newInputFile.type = "file";
	newInputFile.className = "dhxvlt_hidden" + (this.Opera ? " dhxvlt_fo" : "");
	newInputFile.id = "file" + (currentId + 1);
	newInputFile.name = newInputFile.id;
	this.currentFile = newInputFile;
	var self = this;
	newInputFile.onchange = function () {
		return self.addFile();
	};
	
	this.fileContainer.appendChild(newInputFile);
	var fileName = this.getFileName(file.value);
	
	var imgFile = this.getImgFile(fileName);
	var containerData = this.containerDiv;
	if (this.tblListFiles == null) {
		this.tblListFiles = this.createTblListFiles();
		containerData.appendChild(this.tblListFiles);
	}
	var rowListFiles = this.tblListFiles.insertRow(this.tblListFiles.rows.length);
	rowListFiles.setAttribute("fileItemId", currentId);
	rowListFiles.setAttribute("id", "rowListFiles" + currentId);
	rowListFiles.setAttribute("isUpload", "false");
	rowListFiles.setAttribute("fileName", fileName);
	rowListFiles.setAttribute("filePath", filePath);
	rowListFiles.onclick = function () {
		self.selectItem(currentId);
	};
	var cellListFiles = document.createElement("td");
	cellListFiles.align = "center";
	rowListFiles.appendChild(cellListFiles);
	var tblContent = document.createElement("table");
	cellListFiles.appendChild(tblContent);
	tblContent.style.cssText = "border-bottom:1px solid #E2E2E2";
	tblContent.cellPadding = "0px";
	tblContent.cellSpacing = "0px";
	tblContent.border = "0px";
	tblContent.id = "tblContent" + currentId;
	var rowList = tblContent.insertRow(tblContent.rows.length);
	var cellList = document.createElement("td");
	cellList.rowSpan = 2;
	cellList.align = "center";
	cellList.innerHTML = "<img src='" + imgFile + "'/>";
	//if (this.IE) {
		//var span = document.createElement("span");
		//span.style.cssText = "width:40px;height:40px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgFile + " ')";
		//cellList.appendChild(span);
	//} else {
		//cellList.innerHTML = "<img src='" + imgFile + "'/>";
	//}
	
	cellList.style.width = "60px";
	rowList.appendChild(cellList);
	cellList = document.createElement("td");
	cellList.align = "left";
	cellList.vAlign = "bottom";
	cellList.style.cssText = "width:300px;height:30px";
	cellList.innerHTML = "<div class='fileName'><div class='fileName' title='"+fileName+"'>" + fileName +"</div></div> ";
	cellList.className = "fileName";
	rowList.appendChild(cellList);
	cellList = document.createElement("td");
	cellList.style.cssText = "width:140px;height:30px";
	cellList.innerHTML = "<div title='" + this.strings.remove + "' id='dhxvlt_icoremove'></div><a href='javascript:void(0)' class='link dhxvlt_txtremove'>" + this.strings.remove + "</a>";
	cellList.firstChild.onclick = cellList.childNodes[1].onclick = function () {
		self.removeItem(currentId);
	};
	cellList.vAlign = "bottom";
	cellList.align = "center";
	rowList.appendChild(cellList);
	rowList = tblContent.insertRow(tblContent.rows.length);
	cellList = document.createElement("td");
	cellList.align = "left";
	cellList.style.cssText = "width:300px;height:30px";
	rowList.appendChild(cellList);
	cellList = document.createElement("td");
	cellList.style.cssText = "width:140px;height:30px";
	cellList.innerHTML = "<a href='javascript:void(0)' class='link' style='visibility:hidden'>" + this.strings.upload + "</a>";
	cellList.firstChild.onclick = function () {
		self.uploadFile(currentId,fileName,filePath);
		return false;
	};
	cellList.vAlign = "middle";
	cellList.align = "center";
	rowList.appendChild(cellList);
	this.checkFilesLimit();
};
dhtmlXVaultObject.prototype.getFileExtension = function (fileName) {
	var ext = "", arr = fileName.split(".");
	if (arr.length > 1) {
		ext = arr[arr.length - 1].toLowerCase();
	}
	return ext;
};
dhtmlXVaultObject.prototype.getImgFile = function (fileName) {
	var srcImgPic = this.imPath + "ico_image.png";
	var srcImgVideo = this.imPath + "ico_video.png";
	var srcImgSound = this.imPath + "ico_sound.png";
	var srcImgArchives = this.imPath + "ico_zip.png";
	var srcImgFile = this.imPath + "ico_file.png";
	var valueImgPic = "jpg,jpeg,gif,png,bmp,tiff";
	var valueImgVideo = "avi,mpg,mpeg,rm,move";
	var valueImgSound = "wav,mp3,ogg";
	var valueImgArchives = "zip,rar,tar,tgz,arj";
	var ext = this.getFileExtension(fileName);
	if (ext == "") {
		return srcImgFile;
	}
	if (valueImgPic.indexOf(ext) != -1) {
		return srcImgPic;
	}
	if (valueImgVideo.indexOf(ext) != -1) {
		return srcImgVideo;
	}
	if (valueImgSound.indexOf(ext) != -1) {
		return srcImgSound;
	}
	if (valueImgArchives.indexOf(ext) != -1) {
		return srcImgArchives;
	}
	return srcImgFile;
};
dhtmlXVaultObject.prototype.createId = function () {
	return this.counter++;
};
dhtmlXVaultObject.prototype.createTblListFiles = function () {
	var tblListFiles = document.createElement("table");
	tblListFiles.id = "tblListFiles";
	tblListFiles.style.backgroundColor = "#FFFFFF";
	tblListFiles.cellPadding = "0";
	tblListFiles.cellSpacing = "0";
	tblListFiles.border = "0";
	return tblListFiles;
};
dhtmlXVaultObject.prototype.removeItem = function (id) {
	var r = this.getCurrentRowListFiles(id);
	r.parentNode.removeChild(r);
	delete this.fileList[id];
	this.checkFilesLimit();
};
dhtmlXVaultObject.prototype.removeAllItems = function () {
	if (!this.isUploadFile) {
		if (this.tblListFiles != null) {
			var count = this.tblListFiles.rows.length;
			if (count > 0) {
				for (var i = 0; i < count; i++) {
					this.tblListFiles.deleteRow(0);
				}
			}
		}
		this.fileList = {};
	}
	this.checkFilesLimit();
};
dhtmlXVaultObject.prototype.uploadAllItems = function () {
	var flag = -1;
	if (this.tblListFiles != null) {
		if (this.tblListFiles.rows.length > 0) {
			for (var i = 0; i < this.tblListFiles.rows.length; i++) {
				if (this.tblListFiles.rows[i].attributes["isUpload"].value == "false") {
					flag = i;
					break;
				}
			}
			if (flag != -1) {
				this.isUploadFileAll = true;
				var fileItemId = this.tblListFiles.rows[i].attributes["fileItemId"].value;
				var fileName  = this.tblListFiles.rows[i].attributes["fileName"].value;
				var filePath = this.tblListFiles.rows[i].attributes["filePath"].value;
				this.uploadFile(fileItemId,fileName,filePath);
			} else {
				if (this.isUploadFileAll) {
					try {
						this.onUploadComplete(this.objToArray(this.fileList));
					}
					catch (e) {
					}
				}
				this.fileList = {};
				this.isUploadFileAll = false;
			}
		}
		else
		{
			top.asyncbox.alert("请先添加上传文件！","提示");
		}
	}
	else
	{
		top.asyncbox.alert("请先添加上传文件！","提示");
	}
};
dhtmlXVaultObject.prototype.objToArray = function (obj) {
	var res = new Array();
	for (var key in obj) {
		res[res.length] = obj[key];
	}
	return res;
};
dhtmlXVaultObject.prototype.createProgressDemo = function () {
	var srcImgProgress = this.imPath + "pb_demoupload.gif";
	var tblProgress = document.createElement("table");
	tblProgress.cellPadding = "0";
	tblProgress.cellSpacing = "0";
	tblProgress.border = "0";
	tblProgress.style.cssText = "height:10px;width:153px;display:none;";
	tblProgress.id = "progress";
	var row = tblProgress.insertRow(tblProgress.rows.length);
	var cell1 = document.createElement("td");
	cell1.style.cssText = "font-size:1px;border:1px solid #A9AEB3;";
	cell1.innerHTML = "<img src=" + srcImgProgress + " style = 'width:150px;height:8px;'/>";
	row.appendChild(cell1);
	return tblProgress;
};
dhtmlXVaultObject.prototype.createProgressBar = function () {
	var srcImgProgress = this.imPath + "pb_back.gif";
	var srcImgEmpty = this.imPath + "pb_empty.gif";
	var tblProgress = document.createElement("table");
	tblProgress.cellPadding = "0";
	tblProgress.cellSpacing = "0";
	tblProgress.border = "0";
	tblProgress.style.cssText = "height:10px;width:149px;border-bottom:0px !important;display:none";
	tblProgress.id = "progress";
	var row = tblProgress.insertRow(tblProgress.rows.length);
	var cell1 = document.createElement("td");
	cell1.style.cssText = "font-size:1px;background-image:url(" + srcImgProgress + ");width:150px;height:10px;border:1px solid #A9AEB3";
	cell1.align = "right";
	var img = document.createElement("img");
	img.src = srcImgEmpty;
	img.style.width = "100%";
	img.style.height = "7px";
	cell1.appendChild(img);
	row.appendChild(cell1);
	return tblProgress;
};
dhtmlXVaultObject.prototype.createPercentPanel = function () {
	var percentCompleted = document.createElement("div");
	percentCompleted.style.cssText = "font-size:9px;height:8px;position:absolute;left:210px;width:20px;display:none;padding-top:0px";
	percentCompleted.id = "percentCompletedValue";
	return percentCompleted;
};
dhtmlXVaultObject.prototype.endLoading = function (id, isError) {
	this.isUploadFile = false;
	this.progressDemo.style.display = "none";
	this.container.appendChild(this.progressDemo);
	var f = this.fileList[id];
	if (f) {
		f.error = isError;
		f.uploaded = !isError;
	}
	try {
		this.onFileUploaded(f);
	}
	catch (e) {
	}
	if (isError) {
		try {
			this.onUploadComplete(this.objToArray(this.fileList));
		}
		catch (e) {
		}
	}
	var c = this.getCurrentInputFile(id);
	if (c) {
		c.parentNode.removeChild(c);
	}
};
dhtmlXVaultObject.prototype.startRequest = function (id) {
	var xmlHttp = this.createXMLHttpRequest();
	xmlHttp.open("POST", this.pathGetIdHandler, false);
	xmlHttp.send("id=" + id);
	if (xmlHttp.status == 200) {
		if (!xmlHttp.responseText) {
			throw "error";
		}
		this.sessionId = xmlHttp.responseText;
		this.inpUPLOAD_IDENTIFIER.value = this.sessionId;
	} else {
		throw "error";
	}
};
dhtmlXVaultObject.prototype.sendIdSession = function (id) {
		var xmlHttp = this.createXMLHttpRequest();
		xmlHttp.open("post", this.pathGetInfoHandler, false);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
		xmlHttp.send("sessionId=" + this.sessionId);
		if (xmlHttp.status == 200) {
			var res = xmlHttp.responseText;
			if (res) {
				var err = res.split(":");
				if (err[0] == "error") {
					if (err[1] == -2) {
						var f = document.getElementById("dhtmlxVaultUploadFrame");
						if (f) {
							f.src = "about:blank";
						}
						alert(this.printf(this.strings.errors["TooBig"], err[2], err[3]));
					} else {
						if (err[1] == -3) {
							alert(this.printf(this.strings.errors["PostSize"], err[2]));
						}
					}
					throw "error";
				}
				res = parseInt(res, 10);
				if (isNaN(res)) {
					throw "error";
				}
				if (res != -1) {
					var self = this;
					try {
						window.setTimeout(function () {
							self.sendIdSession(id);
						}, 500);
					}
					catch (e) {
					}
				} else {
					if (res == -1) {
						this.uploadedCount++;
						this.endLoading(id, false);
						this.showMessageInfo(id, this.strings.done);
						if (this.isUploadFileAll) {
							this.uploadAllItems();
						}
					}
				}
			}
		} else {
			throw "error";
		}
	
};
dhtmlXVaultObject.prototype.printf = function () {
	var n = arguments.length;
	var str = arguments[0];
	for (var i = 1; i < n; i++) {
		var pattern = "\\{" + (i - 1) + "\\}";
		var re = new RegExp(pattern, "g");
		str = str.replace(re, arguments[i]);
	}
	return str;
};
dhtmlXVaultObject.prototype.showMessageInfo = function (id, msg) {
	var tblContent = this.getCurrentTblContent(id);
	tblContent.rows[1].cells[0].innerHTML += "<font class='text'>" + msg + "</font>";
	tblContent.rows[1].cells[0].vAlign = "top";
};
dhtmlXVaultObject.prototype.showProgressInfo = function (perc) {
	this.tblProgressBar.rows[0].cells[0].firstChild.style.width = 100 - perc + "%";
	this.percentPanel.innerHTML = "<nobr>" + perc + "%</nobr>";
};
dhtmlXVaultObject.prototype.getFilesCount = function () {
	return this.tblListFiles && this.tblListFiles.rows ? this.tblListFiles.rows.length : 0;
};
dhtmlXVaultObject.prototype.getTotalFilesCount = function () {
	var count = this.uploadedCount;
	if (this.tblListFiles != null) {
		if (this.tblListFiles.rows.length > 0) {
			for (var i = 0; i < this.tblListFiles.rows.length; i++) {
				if (this.tblListFiles.rows[i].attributes["isUpload"].value == "false") {
					count++;
				}
			}
		}
	}
	return count;
};
dhtmlXVaultObject.prototype.getCurrentRowListFiles = function (id) {
	for (var i = 0; i < this.tblListFiles.rows.length; i++) {
		if (this.tblListFiles.rows[i].id == "rowListFiles" + id) {
			return this.tblListFiles.rows[i];
		}
	}
};
dhtmlXVaultObject.prototype.getCurrentTblContent = function (id) {
	for (var i = 0; i < this.tblListFiles.rows.length; i++) {
		if (this.tblListFiles.rows[i].cells[0].firstChild.id == "tblContent" + id) {
			return this.tblListFiles.rows[i].cells[0].firstChild;
		}
	}
};
dhtmlXVaultObject.prototype.getFormField = function (type, name) {
	var fields = this.uploadForm.getElementsByTagName("input");
	for (var i = 0; i < fields.length; i++) {
		var f = fields[i];
		if (f.type.toLowerCase() == type && f.name == name) {
			return f;
		}
	}
	return null;
};
dhtmlXVaultObject.prototype.getCurrentInputFile = function (id) {
	return this.getFormField("file", "file" + id);
};
dhtmlXVaultObject.prototype.uploadFile = function (id,fileName,filePath) {
	var ext = this.getFileExtension(fileName);
	
	if(null==this.fileType||""==this.fileType)
	{
		top.asyncbox.alert("文件所属类型不能为空！","提示");
		return;
	}
	if(null==this.businessType||""==this.businessType)
	{
		top.asyncbox.alert("文件所属业务类型不能为空！","提示");
		return;
	}
	if(this.fileType!=null&&this.fileType=='1')
	{
		this.fileExtensionStr = this.imgType;
		this.setFileExtensionList(this.fileExtensionStr);
	}
	else if(this.fileType!=null&&this.fileType=='2')
	{
		this.fileExtensionStr = this.documentType;
		this.setFileExtensionList(this.fileExtensionStr);
	}
	else if(this.fileType!=null&&this.fileType=='3')
	{
		this.fileExtensionStr = this.compressType;
		this.setFileExtensionList(this.fileExtensionStr);
	}
	else if(this.fileType!=null&&this.fileType=='4')
	{
		this.fileExtensionStr = this.video_frequency;
		this.setFileExtensionList(this.fileExtensionStr);
	}
	else if(this.fileType!=null&&this.fileType=='0')
	{
		this.fileExtensionStr = this.otherType;
		this.setFileExtensionList(this.fileExtensionStr);
	}
	if(this.fileExtensionList.in_array(ext)==false)   
	{
		top.asyncbox.alert("文件 "+fileName+" 与所选文件所属类型不匹配，请上传以 "+this.fileExtensionStr+" 结尾的文件！","提示");
		return;
	}
//	if(null==this.fileGrade)
//	{
//		asyncbox.alert("文件级别不能为空！","提示");
//		return;
//	}
	if (!this.isUploadFile) {
		this.selectItem(id);
		var tblContent = this.getCurrentTblContent(id);
		tblContent.rows[0].cells[2].removeChild(tblContent.rows[0].cells[2].firstChild);
		tblContent.rows[1].cells[1].removeChild(tblContent.rows[1].cells[1].firstChild);
		tblContent.parentNode.parentNode.attributes["isUpload"].value = "true";
		this.isUploadFile = true;
		this.getCurrentInputFile(id).disabled = false;
		this.progressDemo.style.display = "inline";
		this.getCurrentRowListFiles(id).cells[0].firstChild.rows[1].cells[0].appendChild(this.progressDemo);
		try {
			this.startRequest(id);
			this.sendIdSession(id);
		}
		catch (e) {
			
			
			this.endLoading(id, true);
			this.isUploadFileAll = false;
			this.isUploadFile = false;
			tblContent.rows[1].cells[0].innerHTML += "<font class='text'>" + this.strings.error + "</font>";
			tblContent.rows[1].cells[0].vAlign = "top";
			return;
		}
		if (!this.isUploadFile) {
			return;
		}
		var sessionidtrim=this.sessionId.replace(/(^\s*)|(\s*$)/g, "");
		jQuery("#uploadForm").attr("action",this.pathUploadHandler + "?sessionId=" +sessionidtrim+ "&parentId="+this.modelRecordId+"&actionName="+this.modelValue+"&businessType="+this.businessType+"&fileGrade="+this.fileGrade+"&fileType="+this.fileType+"&fileName=" + escape(escape(this.getFileName(this.getCurrentInputFile(id).value))) + "&userfile=" + this.getCurrentInputFile(id).id);
		jQuery("#uploadForm").submit();
	}
	
};
dhtmlXVaultObject.prototype.preLoadImages = function () {
	var imSrcAr = new Array("add.gif", "close.gif", "btn1.gif", "btn2.gif", "btn3.gif", "clean.gif", "upload.gif", "delete.gif", "ico_file.png", "ico_image.png", "ico_sound.png", "ico_video.png", "ico_zip.png", "pb_back.gif", "pb_demoupload.gif", "pb_empty.gif", "rowsel.gif");
	var imAr = new Array(imSrcAr.length);
	for (var i = 0; i < imSrcAr.length; i++) {
		imAr[i] = new Image();
		imAr[i].src = this.imPath + imSrcAr[i];
	}
};
dhtmlXVaultObject.prototype.setFilesLimit = function (limit) {
	var n = parseInt(limit);
	if (!isNaN(n) && n >= 0) {
		this.filesLimit = n;
	}
};
dhtmlXVaultObject.prototype.setFormField = function (name, value) {
	if (!this.uploadForm) {
		top.asyncbox.alert("Please call setFormField() method after create()!","");
		return;
	}
	var field = this.getFormField("hidden", name);
	if (value === null) {
		if (field) {
			this.uploadForm.removeChild(field);
		}
	} else {
		if (!field) {
			field = document.createElement("input");
			field.type = "hidden";
			field.name = name;
			this.uploadForm.appendChild(field);
		}
		field.value = value;
	}
};
Array.prototype.in_array = function(e)     
{     
	for(i=0;i<this.length && this[i]!=e;i++);     
	return !(i==this.length);     
}  
dhtmlXVaultObject.prototype.onAddFile = function (fileName) {
	if(this.getFileSize(fileName)>this.MAX_FILE_SIZE)
	{
		var size = this.MAX_FILE_SIZE/1024;	
		top.asyncbox.alert("文件大小不能超过"+size+"KB!","提示");
		return;
	}
	if(this.getTotalFilesCount()<10)
	{
		var ext = this.getFileExtension(fileName);
		
		if(this.fileType==null||this.fileType=="")
		{
			top.asyncbox.alert("请选择文件上传类型!","提示");
			return;
		}
		else if(this.fileType==1)
		{
			this.fileExtensionStr = this.imgType;
			this.setFileExtensionList(this.fileExtensionStr);
		}
		else if(this.fileType!=null&&this.fileType==2)
		{
			this.fileExtensionStr = this.documentType;
			this.setFileExtensionList(this.fileExtensionStr);
		}
		else if(this.fileType!=null&&this.fileType==3)
		{
			this.fileExtensionStr = this.compressType;
			this.setFileExtensionList(this.fileExtensionStr);
		}
		else if(this.fileType!=null&&this.fileType==4)
		{
			this.fileExtensionStr = this.video_frequency;
			this.setFileExtensionList(this.fileExtensionStr);
		}
		else if(this.fileType!=null&&this.fileType==0)
		{
			this.fileExtensionStr = this.otherType;
			this.setFileExtensionList(this.fileExtensionStr);
		}
		if(this.fileExtensionList.in_array(ext)==false)   
		{
			top.asyncbox.alert("请添加以 "+this.fileExtensionStr+" 结尾的文件！","提示");
			return;
		}
		return true;
	}
	else
	{
			top.asyncbox.alert("一次最多只能添加10个文件，添加成功后可清空已上传的文件，继续添加！","提示");
	}
};
dhtmlXVaultObject.prototype.onUploadComplete = function (files) {
};
dhtmlXVaultObject.prototype.onFileUploaded = function (file) {
	this.containerDiv.scrollTop+=32;
};
//v.1.6 build 9757
/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
dhtmlXVaultObject.prototype.getFileSize = function (filePath)　　
{　　
　 var fso = new ActiveXObject("Scripting.FileSystemObject");　　
  var fileSize=fso.GetFile(filePath).size;
  return fileSize;
　
}　

dhtmlXVaultObject.prototype.fileClick = function(){
//	jQuery('#file1').click();
	jQuery('.btnAddDiv input').click();
}


